Skip to content

Replace instance with serverURL in generated code samples#90

Merged
chris-freeman-glean merged 2 commits intomainfrom
cfreeman/server-url-code-samples
Mar 4, 2026
Merged

Replace instance with serverURL in generated code samples#90
chris-freeman-glean merged 2 commits intomainfrom
cfreeman/server-url-code-samples

Conversation

@chris-freeman-glean
Copy link
Contributor

Summary

Migrates generated code samples from using instance to serverURL as the primary configuration parameter. This is part of a broader effort to promote serverURL as the primary way users configure their Glean SDK, replacing the instance concept in all documentation and examples.

What changed

  • Renamed addInstanceToCodeSamplesaddServerURLToCodeSamples in src/code-sample-transformer.js
  • Updated regex transformations for all 4 languages (Python, TypeScript, Go, Java) to inject serverURL instead of instance configuration
  • Updated all test snapshots

Why this goes first

This change must land before Speakeasy SDK regeneration (Phase 3) so that regenerated READMEs automatically use serverURL in their code samples.

Language-specific code sample changes

Language Before After
Python instance=os.environ.get("GLEAN_INSTANCE") server_url="mycompany-be.glean.com"
TypeScript instance: process.env["GLEAN_INSTANCE"] serverURL: "mycompany-be.glean.com"
Go apiclientgo.WithInstance(os.Getenv("GLEAN_INSTANCE")) apiclientgo.WithServerURL("mycompany-be.glean.com")
Java .instance("<value>") .serverURL("mycompany-be.glean.com")

Backwards compatibility

The instance parameter remains in the generated SDK code (from the OpenAPI spec transformer). This change only affects documentation/examples — no breaking changes.

Test plan

  • All 54 existing tests pass with updated snapshots

Update code sample transformer to use hardcoded serverURL values
instead of instance environment variables across Python, TypeScript,
Go, and Java code samples.
@chris-freeman-glean chris-freeman-glean marked this pull request as ready for review March 3, 2026 22:38
@chris-freeman-glean chris-freeman-glean requested a review from a team as a code owner March 3, 2026 22:38
[
/([\s]*)(api_token=os\.getenv\("GLEAN_API_TOKEN", ""\),)/,
'$1$2$1instance=os.getenv("GLEAN_INSTANCE", ""),',
'$1$2$1server_url="mycompany-be.glean.com",',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Missing https:// protocol scheme in serverURL values. The SDK methods (server_url, serverURL, WithServerURL, .serverURL()) require a fully qualified URL (including the protocol) to function correctly. Without the scheme, the generated code will likely fail at runtime (for example, URL parsing errors or invalid requests).

Suggested fix: Update the replacement strings in src/code-sample-transformer.js to include the protocol:

  • Line 98: server_url="https://mycompany-be.glean.com",
  • Line 104: serverURL: "https://mycompany-be.glean.com",
  • Line 110: apiclientgo.WithServerURL("https://mycompany-be.glean.com"),
  • Line 116: .serverURL("https://mycompany-be.glean.com")
    Also update the corresponding expectations in tests/code-sample-transformer.test.js where these literals appear.

💬 Help us improve! Was this comment helpful? React with 👍 or 👎

@chris-freeman-glean chris-freeman-glean merged commit dd5ea2a into main Mar 4, 2026
3 checks passed
@chris-freeman-glean chris-freeman-glean deleted the cfreeman/server-url-code-samples branch March 4, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant